package cn.bugstack.chatglm.interceptor;

import cn.bugstack.chatglm.utils.BearerTokenUtils;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

/**
 * @author 小傅哥，微信：fustack
 * @description 接口拦截器
 * @github https://github.com/fuzhengwei/chatglm-sdk-java
 * @Copyright 公众号：bugstack虫洞栈 | 博客：https://bugstack.cn - 沉淀、分享、成长，让自己和他人都能有所收获！
 */
public class MyOpenAiHTTPInterceptor implements Interceptor {



    @Override
    public @NotNull Response intercept(Chain chain) throws IOException {
        // 1. 获取原始 Request
        Request originalRequest = chain.request();
        // 2. 构建请求
        Request request = originalRequest.newBuilder()
                .url(originalRequest.url())
                .header("Authorization", "Bearer " + BearerTokenUtils.getToken("da545a7f09c95acc5d110834f13ae7a3", "B8wWChClBB0LwyYN"))
                .header("Content-Type", "application/json ; charset=utf-8")
                .header("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)")
//                .header("Accept", null != original.header("Accept") ? original.header("Accept") : Configuration.SSE_CONTENT_TYPE)
                .method(originalRequest.method(), originalRequest.body())
                .build();

        // 3. 返回执行结果
        return chain.proceed(request);
    }

}
